package com.kuang.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author: Zhang Dongwei
 * Date: 2022/4/16 21:30
 */
public class ServletDemo04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = this.getServletContext();
        System.out.println("进入了servletdemo04");
//        RequestDispatcher requestDispatcher = context.getRequestDispatcher("/gp");// 转发的请求路径
//        requestDispatcher.forward(req,resp);// 调用forward实现请求转发；
        context.getRequestDispatcher("/gp").forward(req,resp);// 上面两行合并成一行


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}